package com.updesignsz.admin.mapper;

import com.updesignsz.commom.entity.UserRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * TODO 用户角色
 * Created User: lx
 * Date: 2020/4/28 15:06
 */
@Repository
@Mapper
public interface UserRoleMapper {

    @Select("select * from t_user_role where user_id = #{userId}")
    UserRole getByUserId(@Param("userId") Integer userId);


    @Select("select * from t_user_role where user_id = #{userId} order by created_date desc")
    List<UserRole> findRoleByUserId(@Param("userId") Integer userId);

    @Insert({
            "insert into t_user_role (user_id, role_id, created_date, updated_date, is_removed) ",
            "values (#{userId},#{roleId},NOW(),NOW(),0)"
    })
    void saveUserRole(UserRole userRole);

    @Delete({"delete from t_user_role where user_id = #{userId}"})
    void deleteUserRoleByUserId(@Param("userId") Integer userId);
}
